package com.atguigu.lease.common.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

//@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        //获取所有的枚举类型
        ItemType[] values = ItemType.values();
        //遍历
        for (ItemType itemType : values) {
            if(itemType.getCode().equals(Integer.parseInt(source))){
                return itemType;
            }
        }
        throw new IllegalArgumentException("非法参数");
    }
}
